using System.Collections;
using System.Collections.Generic;
using UnityEngine;

/// <summary>
/// 脚本继承
/// 继承的脚本需挂载到实例上
/// 确保实例唯一
/// </summary>
/// <typeparam name="T">泛型</typeparam>
public class SingletonMonoBehaviour<T> : MonoBehaviour where T : MonoBehaviour
{
    private static T instance;

    public static T Instance
    {
        get
        {
            return instance;
        }
    }

    protected virtual void Awake()
    {
        if(instance == null)
        {
            instance = this as T;
        }
        else
        {
            Destroy(gameObject);
        }
    }
}
